const vscode = require('vscode');
const { GITLAB_COM_URL } = require('./constants');
const { tokenService } = require('./services/token_service');

async function showInput() {

  const token = await vscode.window.showInputBox({
    ignoreFocusOut: true,
    password: true,
    placeHolder: '请在此处粘贴您在 CSDN codechina 平台的用户访问令牌',
  });

  if (token) {
    await tokenService.setToken(GITLAB_COM_URL, token);
  }
}

async function removeTokenPicker() {
  const instanceUrls = tokenService.getInstanceUrls();
  const selectedInstanceUrl = await vscode.window.showQuickPick(instanceUrls, {
    ignoreFocusOut: true,
    placeHolder: '点击 URL 以确认删除用户访问令牌',
  });

  if (selectedInstanceUrl) {
    await tokenService.setToken(selectedInstanceUrl, undefined);
  }
}

exports.showInput = showInput;
exports.removeTokenPicker = removeTokenPicker;
